class UserController < ApplicationController

  layout "main"

  def reg
    @menu_index=4
    @user=User.new(params[:user])
    @user.last_login=DateTime.now
    @user.created_at=DateTime.now
    @user.last_ip=request.remote_ip   #获取用户登录ip
    if request.post? and @user.save
      show_message('注册成功','green')
      session[:username]=@user.name;
    end
  end

  def login
    @user=User.find_by_name(params[:name])
    if @user and @user.password==params[:password]
      session[:userid]=@user.id
      session[:username]=@user.name
    else
      @user=nil
    end
  end

  def logout
    session[:userid]=nil;
    session[:username]=nil;
    render :partial=>'layouts/login'
  end

  def show
  end
end
